package com.rising.face.bytes.P1_链表翻转;

import com.rising.leetcode.editor.cn.doc.object.ListNode;

/**
 * @Author: rising
 * @Description: 给你单链表的头节点 head ，请你反转链表，并返回反转后的链表。
 * @Date: create in 2023/1/17 15:40
 */
public class ReverseList {
    public ListNode reverseList(ListNode head) {
        ListNode next = null;
        ListNode pre = null;
        while (head != null) {
            //取出下个节点
            next = head.next;
            //翻转
            head.next = pre;
            pre = head;
            if (next == null) {
                break;
            }
            head = next;
        }
        return head;
    }
}
